// Next.js适配器，处理Taro组件在Next.js环境中的兼容性
import React from 'react';

// 为Next.js环境提供Taro的运行时环境
if (typeof window !== 'undefined') {
  // 在浏览器环境中模拟Taro的全局对象
  (window as any).__TARO_ENV__ = 'h5';
  (window as any).__TARO_FRAMEWORK__ = 'react';
}

// 导出Taro组件，确保在Next.js中正常工作
export { View, Text, Button, Image, Input, Textarea, ScrollView } from '@tarojs/components';

// 提供Taro的API兼容性
export const Taro = {
  // 页面导航
  navigateTo: (options: { url: string }) => {
    if (typeof window !== 'undefined') {
      window.location.href = options.url;
    }
  },

  // 显示提示
  showToast: (options: { title: string; icon?: string }) => {
    if (typeof window !== 'undefined') {
      alert(options.title);
    }
  },

  // 获取系统信息
  getSystemInfo: () => {
    if (typeof window !== 'undefined') {
      return {
        platform: 'web',
        screenWidth: window.screen.width,
        screenHeight: window.screen.height,
        windowWidth: window.innerWidth,
        windowHeight: window.innerHeight,
      };
    }
    return {
      platform: 'web',
      screenWidth: 375,
      screenHeight: 667,
      windowWidth: 375,
      windowHeight: 667,
    };
  },
};

// 导出默认的Taro对象
export default Taro;
